package com.sql.parse.ognl;


import com.sql.parse.PlaceHolder;

import java.util.Collection;

public class MyDynamicSqlSource implements MySqlSource {

    private Collection<PlaceHolder> placeHolders;
    private DataNode rootSqlNode;


    public MyDynamicSqlSource(DataNode rootSqlNode, Collection<PlaceHolder> placeHolders) {
        this.rootSqlNode = rootSqlNode;
        this.placeHolders = placeHolders;
    }


    @Override
    public MyDynamicContext getSqlContext(Object parameterObject) {
        MyDynamicContext context = new MyDynamicContext(parameterObject, placeHolders);
        rootSqlNode.apply(context);
        return context;
    }

   /* @Override
    public BoundSql getBoundSql(Object parameterObject) {
        MyDynamicContext context = new MyDynamicContext(parameterObject);
        rootSqlNode.apply(context);
        System.out.println(context.getSql());
        SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(Constants.CONFIGURATION);
        Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
        SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
        BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
        for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
            boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
        }
        return boundSql;
    }*/

}
